package com.lsj.webSpring.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.lsj.webSpring.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Lsj
 * @version 1.0
 * @date 2021/6/28 18:34
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @RequestMapping(value = "list", method = RequestMethod.GET)
    public String list() {
        return "user/list";
    }

//    /**
//     * @RequestMapping(value = "add",method = RequestMethod.POST)
//     * @return post请求
//     */
//    @PostMapping(value = "add",params = {"name"},headers = {"token"})
//    public String add(HttpServletRequest request){
//        String name = request.getParameter("name");
////        System.out.println(name);
//        return "user/add";
//    }
//
//    /**
//     * @RequestMapping(value = "add",method = RequestMethod.POST)
//     * @return post请求
//     */
//    @PostMapping(value = "add",params = {"name"},headers = {"token"})
//    public String add(String name,@RequestParam(value = "studentAge",required = false) Integer age){
//        System.out.println(name);
//        System.out.println(age);
//        return "user/add";
//    }

    /**
     * @return post请求
     * RequestMapping(value = "add",method = RequestMethod.POST)
     */
    @PostMapping(value = "add", headers = {"token"})
    public String add(User user, HttpServletRequest request, HttpServletResponse response) {
        System.out.println(user.getBirthday());
        return "user/add";
    }
}
